package com.education.wisdom.service.impl;

import com.education.common.utils.Convert;
import com.education.common.utils.UUIDUtils;
import com.education.wisdom.mapper.MsQuestionsMapper;
import com.education.wisdom.pojo.MsQuestions;
import com.education.wisdom.service.IMsQuestionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 试题 服务层实现
 * 
 * @author ruoyi
 * @date 2018-12-17
 */
@Service
public class MsQuestionsServiceImpl implements IMsQuestionsService
{
	@Autowired
	private com.education.wisdom.mapper.MsQuestionsMapper MsQuestionsMapper;

	/**
     * 查询试题信息
     * 
     * @param id 试题ID
     * @return 试题信息
     */
    @Override
	public MsQuestions selectMsQuestionsById(Integer id)
	{
	    return MsQuestionsMapper.selectMsQuestionsById(id);
	}

	/**
	 * 查询试题信息
	 *
	 * @param id 试题ID
	 * @return 试题信息
	 */
	@Override
	public MsQuestions selectMsQuestionsByIds(String stId) {
		return MsQuestionsMapper.selectMsQuestionsByIds(stId);
	}

	/**
     * 查询试题列表
     * 
     * @param MsQuestions 试题信息
     * @return 试题集合
     */
	@Override
	public List<MsQuestions> selectMsQuestionsList(MsQuestions MsQuestions)
	{
	    return MsQuestionsMapper.selectMsQuestionsList(MsQuestions);
	}
	
    /**
     * 新增试题
     * 
     * @param MsQuestions 试题信息
     * @return 结果
     */
	@Override
	public int insertMsQuestions(MsQuestions MsQuestions)
	{
		MsQuestions.setStId(UUIDUtils.getByUUId());
		MsQuestions.setCreateTime(new Date());
	    return MsQuestionsMapper.insertMsQuestions(MsQuestions);
	}
	
	/**
     * 修改试题
     * 
     * @param MsQuestions 试题信息
     * @return 结果
     */
	@Override
	public int updateMsQuestions(MsQuestions MsQuestions)
	{
	    return MsQuestionsMapper.updateMsQuestions(MsQuestions);
	}

	/**
     * 删除试题对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteMsQuestionsByIds(String ids)
	{
		return MsQuestionsMapper.deleteMsQuestionsByIds(Convert.toStrArray(ids));
	}

	@Override
	public List<MsQuestions> selectQuestionsByPaperId(Integer paperId) {

		List<MsQuestions> questions1=MsQuestionsMapper.selectQuestionsByPaperId(paperId);
		List<MsQuestions> questions2=selectAllQuestions();
		for(MsQuestions question2:questions2){
			for(MsQuestions question1:questions1){
				if(question2.getId().intValue()==question1.getId().intValue()){
					question2.setFlag(true);
					break;
				}
			}
		}

		return questions2;
	}

	@Override
	public List<MsQuestions> selectQuestionsByPaper(Integer paperId) {
		return  MsQuestionsMapper.selectQuestionsByPaperId(paperId);
	}

	@Override
	public List<MsQuestions> selectAllQuestions() {
		return selectMsQuestionsList(new MsQuestions());
	}
	
}
